<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8"/>
    <title>微信文章</title>
    <link rel="stylesheet" type="text/css" media="all" href="/layui/css/layui.css"/>
    <script type="text/javascript" src="/layui/layui.all.js"></script>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap.js"></script>
    <script type="text/javascript" src="/js/myJs.js"></script>
    <link rel="stylesheet" type="text/css" media="all" href="/css/common.css"/>
    <link rel="stylesheet" type="text/css" media="all" href="/css/CaseManager.css"/>
</head>
<body>
<br/>
<div class="layui-col-xs-offset11">
    <div id="tuichu1"></div>
</div>
<!--主内容-->
<div class="layui-fluid">
    <div class="layui-col-xs12">
        <div style="width: 160px; font-weight: bolder; font-size: large; margin-top: 20px; margin-left: auto; margin-right: auto">文章列表</div>
        <br/><br/>

<!--        <div class="layui-inline">
            <label class="layui-form-label">上传时间：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="Startime" placeholder=" 开始时间 "/>
            </div> ——
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="Endtime" placeholder=" 结束时间 "/>
            </div>
        </div>
        <button class="layui-btn" data-type="reload">搜索</button>-->
        <div class="layui-col-xs4">
            分类选择：
            <div class="layui-input-inline" style="width: 160px;">
                <div class="layui-form">
                    <select name="ArticleType" id="ArticleType">
                        <option value="">全部</option>
                    </select>
                </div>
            </div>
            <button class="layui-btn" data-type="reload">搜索</button>
        </div>
        <div class="layui-col-md-offset11">
            <a  class="layui-btn layui-btn-primary" onclick="backHome()">返回</a>
        </div>
        <table class="layui-table" id="brokerVideoID" lay-filter="table"></table>

    </div>
</div>


<script>
    $.get(
        "/Request/typeSelect", {

        }, function (data) {
            var objectD = JSON.parse(data);
            $.each (objectD.rows, function (key, value) {
                if (value.name.indexOf("微信") != -1){
                    var result = '<option value="' + value.type + '">' + value.name.substr(5,value.name.length) + '</option>';
                    $('#ArticleType').append(result);
                }
            })
            layui.use('form', function(){
                var form = layui.form;
                form.render();
            });
        }
    )
    function zhuxiao(){
        var storage = window.localStorage;
        storage.clear();
    }
    function backHome(){
        loadPage("/plateForm/homepage")
    }
    $(function () {
        var storage = window.localStorage;
        var result ='<br/><br/><div>'+storage.username+'    <a href="/plateForm/login" onclick="zhuxiao()" style="color: #1E9FFF;font-weight:bold">( 注销 ) </a>'+'</div>';
        $('#tuichu1').append(result);
        layui.use('form', function(){
            var form = layui.form;
            form.render();
        });
/*        var it =JSON.parse(localStorage.getItem("username"))
        if (it == null){
            loadPage("/plateForm/login")
        }*/
    })
    layui.use('form', function(){
        var form = layui.form;
        form.render();
    });
    layui.use('table', function(){
        var table = layui.table,$ = layui.jquery;
        table.render({
            elem: '#brokerVideoID'
            ,url:'/Request/getArticle'
            ,cellMinWidth: 80
            ,page: true
            ,cols: [[
                {field:'dtCreateTime', title: '上传时间', align:'center', width: 180}
                ,{field:'title', title: '标题',  align:'center', minWidth: 300}
                ,{field:'downCount', title: '下载次数', align:'center', width: 100}
                ,{field:'readCount', title: '浏览次数', align:'center', width: 100}
                ,{fixed: 'right', width:180, align:'center', toolbar: '#sourceTool'}
            ]],
            where:{
                ArticleType:''
            },
            request: {
                pageName: 'pageNumber',
                limitName: 'pageSize'
            },
            response: {
                countName: 'total',
                dataName: 'rows'
            }
        });
        var $ = layui.$, active = {
            /*表格重载*/
            reload: function(){
                var ArticleType = $('#ArticleType');
                table.reload('brokerVideoID', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        ArticleType: ArticleType.val()
                    }
                });
            },
        };
        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        table.on('tool(table)', function(obj){
            var data = obj.data;
            if(obj.event === '在线预览'){
                loadPageWithBlank("/plateForm/ArticleDetail?sourseID="+data.sourseID)
            }else if(obj.event ==='down'){
                var url="/download/GetResource";
                var file = data.fileName;
                var storages = window.localStorage;
                var user = storages.username;
                var form = $("<form></form>").attr("action", url).attr("method", "get");
                form.append($("<input></input>").attr("type", "hidden").attr("name", "fileName").attr("value",file))
                form.append($("<input></input>").attr("type", "hidden").attr("name","username").attr("value",user));
                form.appendTo('body').submit().remove();
            }
        });
    });

</script>

<div class="fly-footer" style="margin-right: auto; margin-left: auto; width: 200px;">
    <p><a href="#" target="_blank">我打 - 资源分享</a> 2018</p>
</div>

</body>

<script type="text/html" id="sourceTool">
    <a class="layui-btn layui-btn-xs" lay-event="在线预览">在线预览</a>
    <!--<a class="layui-btn layui-btn-xs" lay-event="down">点击下载</a>-->
</script>

</html>